package net.neiquan.applibrary.wight;

import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.TextView;

public class PingItemView extends TextView {

	private static final StringBuffer sb = new StringBuffer();
	private static final LinearLayout.LayoutParams l1 = new LinearLayout.LayoutParams(-1, -1);
	private static final int grv = Gravity.LEFT | Gravity.CENTER_VERTICAL;
	private static final int color = Color.rgb(0x66, 0x66, 0x66);
	private static final ForegroundColorSpan cspan = new ForegroundColorSpan(Color.rgb(0x00, 0x99, 0xcc));
	private static final ForegroundColorSpan cspan2 = new ForegroundColorSpan(Color.rgb(0x00, 0x99, 0xcc));

	public PingItemView(Context context) {
		super(context);
		init(context);
	}

	private void init(Context context) {
		setGravity(Gravity.CENTER_VERTICAL);
		l1.bottomMargin=8;
		setLayoutParams(l1);
		setTextSize(13.5f);
		setGravity(grv);
		setTextColor(color);
	}

	// 
	/**
	 * 如果是回复  第二个名字 要填写没有的话null
	 * A 回复B haha 
	 * A :haha
	 * @param name1
	 * @param name2
	 * @param content
	 */
	public void setTxt(String name1,String name2 ,String content) {
		sb.delete(0, sb.length());
		SpannableString sp1 = null;
		// 查看更多;
		setText("");
		if(name1==null &&  name2==null ){
			//
		}
		// 评论
		else if (name2==null) {
			sp1 = new SpannableString(sb.append(name1).append(" : ").toString());
			sp1.setSpan(cspan, 0, sp1.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
			setText(sp1);
		}else{
			// 回复
			sp1 = new SpannableString(sb.append(name1).append("").toString());
			sp1.setSpan(cspan, 0, sp1.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
			setText(sp1);
			append(" 回复 ");
			sb.delete(0, sb.length());
			SpannableString sp2 =new SpannableString(sb.append(name2).append(" : ").toString());
			sp2.setSpan(cspan2, 0, sp2.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
			append(sp2);
			
		}
		append(content);
	}

}

